package com.softer.wxzj.common.logic;

import com.softer.wxzj.common.enums.NumStrEnum;
import com.softer.wxzj.common.util.StringUtils;
import com.softer.wxzj.mapper.SysOperatorMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.math.BigInteger;

@Component
public class GenerateAccount {
    @Autowired
    private SysOperatorMapper sysOperatorMapper;

    /**
     * 生成账号
     *
     * @param type
     * @return
     */
    public synchronized String generateAccount(String type) {
        String regNo = sysOperatorMapper.selectMaxOperNo(type);
        BigInteger add = new BigInteger(NumStrEnum.ONE.getNum());
        String typeNo = "000001";
        if (!StringUtils.isBlank(regNo)) {
            BigInteger reeNo = new BigInteger(regNo);
            reeNo = reeNo.add(add);
            typeNo = String.format("%06d", reeNo);
        }
        //开发企业6开头
        switch (type) {
            case "01":
                regNo = "kf" + typeNo;
                break;
            case "02":
                regNo = "wy" + typeNo;
                break;
            case "03":
                regNo = "wx" + typeNo;
                break;
            case "04":
                regNo = "jl" + typeNo;
                break;
            case "05":
                regNo = "yw" + typeNo;
                break;
            case "06":
                regNo = "jw" + typeNo;
                break;
            case "08":
                regNo = "sj" + typeNo;
                break;
            default:
                regNo = "gr" + typeNo;
                break;
        }

        return regNo;
    }
}
